﻿using System;
using System.Drawing;
using System.Windows.Forms;
using SampleFramework;
using SlimDX;
using SlimDX.Direct3D9;

namespace Nimue
{
    class Nimue : Game
    {
        #region Constants
        const int InitialWidth = 800;
        const int InitialHeight = 600;
        #endregion

        #region Fields
        private DeviceSettings deviceSettings;
        #endregion

        #region Public Properties
        public Device Device
        {
            get { return GraphicsDeviceManager.Direct3D9.Device; }
        }

        public DeviceSettings CurrentSettings
        {
            get { return GraphicsDeviceManager.CurrentSettings; }
        }

        public Color ClearColor
        {
            get;
            set;
        }
        #endregion

        #region Constructor
        public Nimue()
        {
            ClearColor = Color.CornflowerBlue;

            Window.ClientSize = new Size(InitialWidth, InitialHeight);
            Window.Text = "Nimue";
            Window.KeyDown += Window_KeyDown;

            deviceSettings = new DeviceSettings();
            deviceSettings.BackBufferCount = 1;
            deviceSettings.BackBufferFormat = Format.X8R8G8B8;
            deviceSettings.BackBufferHeight = InitialHeight;
            deviceSettings.BackBufferWidth = InitialWidth;
            deviceSettings.DepthStencilFormat = Format.D32;
            deviceSettings.DeviceType = DeviceType.Hardware;
            deviceSettings.DeviceVersion = DeviceVersion.Direct3D9;
            deviceSettings.EnableVSync = false;
            deviceSettings.Windowed = true;

            GraphicsDeviceManager.ChangeDevice(deviceSettings);
            
            this.IsFixedTimeStep = false;
        }
        #endregion

        #region Hard-coded Exit Button
        void Window_KeyDown(object sender, KeyEventArgs e)
        {
            // F1 toggles between full screen and windowed mode
            // Escape quits the application
            if (e.KeyCode == Keys.F1)
                GraphicsDeviceManager.ToggleFullScreen();
            else if (e.KeyCode == Keys.Escape)
                Exit();
        }
        #endregion

        #region Load Content
        protected override void LoadContent()
        {
        }
        #endregion

        #region Unload Content
        protected override void UnloadContent()
        {
        }
        #endregion

        #region Draw
        protected override void Draw(GameTime gameTime)
        {
            Device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, ClearColor, 1.0f, 0);
        }
        #endregion
    }
}
